import Mock from "mockjs";
// 描述函数
const Random = Mock.Random;
// 引入token名
// import {tokenName} from "@/config/globalConfig.ts"

import {successResponseWrap, failResponseWrap} from "@/mock/utils/util.ts"

// 登录获取token
const login = Mock.mock(new RegExp("/api/user/login"), 'post', (params: any) => {
    const userInfo: {username: string, password: string} = JSON.parse(params.body);
    const backAuth: Array<string> = [];
    if(userInfo.username == 'admin') backAuth.push('admin');
    return successResponseWrap({
        token: 'admin',
        authorities: backAuth,
        username: userInfo.username,
        avatar: Random.image('200x100')
    })
})

const getInfo = Mock.mock(new RegExp("/api/user/info"), "get", () => {
    return successResponseWrap({
        token: 'admin',
        authorities: ['admin'],
        username: 'admin',
        avatar: Random.image('200x100')
    })
})

const logout = Mock.mock(new RegExp("/api/user/logout"), "post", () => {
    return failResponseWrap(null, "退出登录失败", 401);
})

export default {
    login,
    getInfo,
    logout
}